const path = require('path');
const resolve = (dir) => {
  return path.join(__dirname, dir);
};
const version = +new Date();
module.exports = {
  publicPath: './',
  outputDir: 'dist',
  assetsDir: 'static',
  lintOnSave: process.env.NODE_ENV !== 'production',
  runtimeCompiler: false,
  productionSourceMap: false,
  filenameHashing: false,//打包文件名称是否要添加hash
  integrity: false,
  devServer: {
    port: '8899',
    hot: true
    // proxy: {
    //   "/api": {
    //     target: "代理的地址",
    //     changeOrigin: true,
    //     secure: false,
    //     pathRewrite: {
    //       "^/api": ""
    //     }
    //   }
    // }
  },
  // chainWebpack是直接修改内置的webpack配置项 configureWebpack是合并webpack默认的配置项
  chainWebpack: (config) => {
     // 移除 prefetch 插件
    config.plugins.delete('prefetch-index')
    // 移除 preload 插件
    config.plugins.delete('preload-index')
    config
      .module
      .rule('images')
      .test(/\.(jpg|png|gif)$/)
      .use('url-loader')
      .loader('url-loader')
      .options({
        limit: 10,
        esModule: false,
        // publicPath: pubPath,
        outputPath: 'static/img',
        name: `[name].${version}.[ext]`
      })
      .end();
  },
  css: {
    extract: {
      filename: `static/css/[name].${version}.css`,
      chunkFilename: `static/css/[name].${version}.css`
    },
    sourceMap: false
  },
  configureWebpack: (config) => {
    Object.assign(config, {
      output: {
        ...config.output,
        filename: `static/js/[name].${version}.js`,
        chunkFilename: `static/js/[name].${version}.js`
      }});
    config.resolve = {
      extensions: ['.js', '.vue', '.json', '.css'], // 引用文件时不需要加后缀
      alias: {
        '@': resolve('src')
      }
    };
  }
}
